/*
 * 人人信用管理有限公司版权所有.
 * 
 * @Description:
 * 
 * @author: liyuliang
 * 
 * @date: 20 Apr 2017 10:44:16 am
 * 
 * 注意：本内容仅限于人人信用管理有限公司内部传阅，禁止外泄以及用于其他的商业目的.
 */

package com.rrx360.common.web.filter;

import java.io.IOException;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import org.sitemesh.builder.SiteMeshFilterBuilder;
import org.sitemesh.config.ConfigurableSiteMeshFilter;

import com.rrx360.common.web.matcher.ServletPathMatcher;
import com.rrx360.common.web.sitemesh.RDecoratorSelector;

public class RSiteMeshFilter extends ConfigurableSiteMeshFilter {

  private ServletPathMatcher pathMatcher;

  private boolean userTemplateSelector = false;



  public boolean isUserTemplateSelector() {
    return userTemplateSelector;
  }



  public void setUserTemplateSelector(boolean userTemplateSelector) {
    this.userTemplateSelector = userTemplateSelector;
  }



  public ServletPathMatcher getPathMatcher() {
    return pathMatcher;
  }



  public void setPathMatcher(ServletPathMatcher pathMatcher) {
    this.pathMatcher = pathMatcher;
  }



  public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,
      FilterChain filterChain) throws IOException, ServletException {
    if (pathMatcher != null && pathMatcher.match((HttpServletRequest) servletRequest)) {
      super.doFilter(servletRequest, servletResponse, filterChain);
    } else {
      filterChain.doFilter(servletRequest, servletResponse);
    }

  }

  protected void applyCustomConfiguration(SiteMeshFilterBuilder builder) {
    RDecoratorSelector selector = new RDecoratorSelector(builder.getDecoratorSelector());
    builder.setCustomDecoratorSelector(selector);
  }



}
